<template>
  <div class="temWrap">
    <div class="wrap" id="wrap">
      <div class="container" @scroll.native="toUpper">
        <topMenu ></topMenu>
        <swiper1 v-if="hackReset"></swiper1>
        <announcement :announcementList='announcementList' v-if="hackReset"></announcement>
        <classification></classification>
        <div class="recommend_Ttile">--为你推荐得最新得好职位--</div>
        <workList :workList="workList1"></workList>
      </div>
    </div>
    
    <footerNav :select1="select"></footerNav>
  </div>
</template>
<script>
  import swiper1 from '@/components/swiper'
  import footerNav from '@/components/footerNav'
  import topMenu from '@/components/topMenu'
  import classification from '@/components/classification'
  import workList from '@/components/workList'
  import BScroll from 'better-scroll'
  import areaJson from '@/assets/area';
  import announcement from '@/components/announcement';
  export default {
    name:'home',
    data() {
      return {
        aScorll: "",
        select: '0',
        workList1: [],
        announcementList:'',
        hackReset:''//强制刷新组件
      }
    },

    components: {
      swiper1,
      topMenu,
      classification,
      workList,
      footerNav,
      announcement
    },

    methods: {
      offsetHeight(value) {
        let tag;
        if (value > -50) {
          tag = false
        } else {
          tag = true
        }
        this.$store.dispatch('setScrollTag', tag)  //这里时设置顶部导航条的颜色
      },
      _initScorll() {
        this.aScorll = new BScroll(document.querySelector('.wrap'), { click: true})   //使用$.ref获取标记   这里要家上probeType:2  不然就会无法派发scroll事件
      },
      async initMap() {
        // let geolocation = new BMap.Geolocation();
        // geolocation.getCurrentPosition((r) => {
        //   this.area = [r.address.province, r.address.city, r.address.district];
        //   console.log(this.area)
        // });
        let _this=this;
        let areaKey=''
        let geolocation = new BMap.Geolocation();  
        let gc = new BMap.Geocoder(); 
        await geolocation.getCurrentPosition( (r)=>{
            let pt = r.point; //获取当前ip的经纬度 
            gc.getLocation(pt, function(rs){  
            let addComp = rs.addressComponents;  
            // console.log(addComp.district)
            // alert(addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber);  
            for(let p in areaJson.county_list){
            if(areaJson.county_list[p]==addComp.district){
              areaKey=p;
              break;
            }
          } 
            _this.area = [addComp.province,addComp.city,addComp.district,areaKey];
        });
        })
         

      },
      async getWorkList(industry_id = "", job_id = "", province = "", city = "", area = "", salary_type = "", salary_range = "") {
        let res = await this.$axios.get(this.$api_url + '/position/getPositionList', {
          params: {
            is_top:1,
            trade_id: industry_id,
            job_id: job_id,
            province:city, 
            city: area,
            salary_type: salary_type,
            salary_range: salary_range
          }
        })
        this.workList1 = res.data.data;
        for (let [index, value] of this.workList1.entries()) {
          value.sex = this.$currency.sexTag1(value.sex)
        }
      },
      async getAnnouncement(){
         let res=await this.$axios('https://wx.zhaowea.com/api/other/get-notice-list');
         this.announcementList=res.data.data
      },
    },
    mounted() {
      this.initMap();
      this.getAnnouncement()
    },
    computed: {
      area: {
        get: function () {
          return this.$store.state.modulesIndex.area
        },
        set: function (newValue) {
          this.$store.dispatch('setArea', newValue);
          
        }
      },
    },
    watch:{
      area(newValue){
        this.getWorkList("", "", newValue[0], newValue[1], newValue[2], "", "")
      }
    },
    created() {
      this.$nextTick(() => {
        // this._initScorll()
      })
      console.log(window.location.href)

    },
    activated() {
      this.hackReset = false
      this.$nextTick(() => {
      this.hackReset = true
      })
    },
  }
</script>

<style scoped>
  .container {
    padding-bottom: 120px;
  }

  .wrap, .temWrap {
    width: 100%;
    height: 100%;
    padding-bottom: 60px;
  }

  .container {
    width: 100%;
  }

  .recommend_Ttile {
    width: 100%;
    text-align: center;
    margin-top: 20px;
    margin-bottom: 10px;
  }
</style>
